import json
import time

from appium import webdriver
from selenium.webdriver.common.by import By


def get_msg():
    msg=UtilsDriver.get_driver().find_element(By.ID,"com.bjcsxq.chat.carfriend:id/txt_msg").text
    return msg

def get_case_data(filename):
    with open(filename, encoding='utf-8') as f:
        case_data = json.load(f)
    list_case_data = []
    for case in case_data:
        for x in case.values():  # values() 用来获取字典对象里面的键值
            case_tuple = x.values()
            list_case_data.append(tuple(case_tuple))
    return list_case_data

class UtilsDriver:
    _driver=None
    @classmethod
    def get_driver(cls):
        if cls._driver is None:
            des_cap = {
                "platformName": "android",
                "deviceName": "****",
                "appPackage": "com.bjcsxq.chat.carfriend",
                "appActivity": ".module_main.activity.SplashActivity",
                "noReset": True,
                "resetKeyboard": True,
                "unicodeKeyboard": True
            }
            cls._driver = webdriver.Remote("http://localhost:4723/wd/hub", des_cap)
            time.sleep(15)
        return cls._driver

    # 定义一个退出浏览器驱动对象的方法
    @classmethod
    def quit_driver(cls):
        if cls._driver is not None:
            cls._driver.quit()
            cls._driver=None

